package com.hp.attendance.serlvet.empmanage.lizhi;

import com.hp.attendance.entity.History;
import com.hp.attendance.service.HistoryService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//离休人员的信息修改
@WebServlet("/historyLXUpdate")
public class EmpManageLXHistoryUpdateServlet extends HttpServlet {
    private HistoryService historyService = new HistoryService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            int id = Integer.parseInt(req.getParameter("id"));
            String name = req.getParameter("name");//姓名
            String gender = req.getParameter("gender");//性别
            String brithday = req.getParameter("date");//出生年日
            Date birthday1 = null;
            try {
                birthday1 = new SimpleDateFormat("yyyy-MM-dd").parse(brithday);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            String telephone = req.getParameter("telephone");//联系方式
            String email = req.getParameter("email");//邮箱
            String address = req.getParameter("address");//籍贯
            String education = req.getParameter("education");//学历
            String home = req.getParameter("home");//家庭住址
            String notes = req.getParameter("notes");//备注
            History history = new History(id, name, gender, birthday1, telephone, email, address, education, home, notes);
            historyService.historyUpdate(history);
            req.getRequestDispatcher("/empMangeLZList").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
